<!-- Content unit - One column -->
<div class="column1-unit">
 	<div class="contactform" style="border:none;background:none;">
 	<!--  -->
		<form id="habits" method="post" action="/diastole/patient/savehabits/<?php echo $habit["patient_id"];?>">
			<input type="hidden" id="habit_id" name="id" value="<?php echo $habit["id"]; ?>"/>
            <div class="column1-unit">
            	<h3>Temperamento</h3>
                <p>
                	<label for="angry" class="left">Facilidad de enojo:</label> 
                    <select name="angry_level" id="angry" class="combo">
                    	<option value="0">Seleccione...</option>
                       	<?php
                            for($i = 0; $i < count($angryLevels); $i++){
                        ?>
                            <option value="<?php echo $i+1; ?>" <?php if ( $habit["angry_level"] == $i+1) echo 'selected="selected"';?>>
                            	<?php echo $angryLevels[$i]; ?>
                            </option>       
                        <?php } ?>
                     </select>
               	</p>
                <p>
                	<label for="stress" class="left">Nivel de Stress Actual:</label> 
                   	<select name="stress_level" id="stress" class="combo">
                   		<option value="0">Seleccione...</option>
                        <?php
                        	for($i=0; $i < count($stressLevels); $i++){
                        ?>
                        	<option value="<?php echo $i+1; ?>" <?php if ($habit["stress_level"]==$i+1) echo 'selected="selected"'; ?>>
                            	<?php echo $stressLevels[$i]; ?>
                            </option>       
                        <?php } ?>
                                                
                  	</select>
               	</p>
            </div>

            <br/>
                                
            <div class="column1-unit">
            	<h3>Vida Cotidiana</h3>
                <p>
                	<label for="sedentary" class="left">Sedentario:</label>
                    <!--  value="Masculino"-->
                    <input type="checkbox" name="sedentary" id="sedentary" tabindex="1" value="<?php echo $habit["sedentary"];?>" <?php echo $habit["sedentary_check"];  ?>  />
                </p>
                <p>
                	<label for="blocks_walked_per_day" class="left">Cuadras diarias caminadas:</label> 
                    <input type="text" name="blocks_walked_per_day" id="blocks_walked_per_day" class="field" value="<?php echo $habit["blocks_per_day"]; ?>" tabindex="2" />
                </p>
                <br/>
                <p>
                	<label for="work_place" class="left">Lugar de trabajo:</label>
                    <input type="text" name="work_place" id="work_place" class="field" value="<?php echo $habit["workplace"]; ?>" tabindex="3" />
                </p>
         	</div>
            
            <br/>
                                
            <div class="column1-unit">
            	<h3>Vicios</h3>
            	<p>    
                    <label for="consume_alcohol" class="left">Bebe Alcohol:</label> 
                    <input type="checkbox" name="consume_alcohol" id="consume_alcohol" value="<?php echo $habit["consume_alcohol"]; ?>"  <?php echo $habit["consume_alcohol_check"];?> tabindex="7" />
                </p>
                <p>
                	<label for="automedication" class="left">Se Automedica:</label> 
                    <input type="checkbox" name="automedication" id="automedication" value="<?php  echo $habit["automedication"]; ?>" <?php echo $habit["automedication_check"];?> tabindex="7" />
                </p>
                <p>
                	<label for="smoke" class="left">Fumador:</label>
                    <input type="radio" name="smoke" id="not-smoked"  value="1" tabindex="3" <?php echo $habit["not_smoked_check"]; ?>/><label style="margin-left:2px;margin-right:2em;">Nunca ha fumado</label>
                    <input type="radio" name="smoke" id="has-smoked" value="2" tabindex="4" <?php echo $habit["has_smoked_check"]; ?>/><label style="margin-left:2px;margin-right:2em;">Dejo de fumar</label>
                    <input type="radio" name="smoke" id="still-smokes" value="3" tabindex="4" <?php echo $habit["still_smokes_check"]; ?>/><label style="margin-left:2px;margin-right:2em;">Fuma actualmente</label>
                </p>
                <p>
                	<label for="cigarettes_per_day" class="left">Cigarrillos diarios:</label>
                    <input type="text" name="cigarettes_per_day" id="cigarettes_per_day" class="field" value="<?php echo $habit["cigarettes_per_day"]; ?>" tabindex="3" />
                </p>
                <p>
                	<label for="years_old_at_smooke_start" class="left">Edad Inicio:</label> 
                    <input type="text" name="years_old_at_smooke_start" id="years_old_at_smooke_start" class="field" value="<?php echo $habit["smoke_start"]; ?>" tabindex="7" />
                </p>    
                <p>
                	<label for="years_old_at_smooke_finish" class="left">Edad Fin:</label> 
                    <input type="text" name="years_old_at_smooke_finish" id="years_old_at_smooke_finish" class="field" value="<?php echo $habit["smoke_end"]; ?>" tabindex="7" />
                </p>
                
                
         	</div>  
                                
            <br/>
                              
            <h3>Actividades</h3>
            <div id="sports" class="column1-unit">
            	<?php echo $activities_content;?>
            </div>
                                                
            <br/>
                                                               
            <p>
            	<input type="button" name="submit" id="submit" class="button" value="Guardar" tabindex="13" />
                <input type="reset" name="reset" id="reset" class="button" value="Cancelar" tabindex="14" />
            </p>
		</form>
	</div>
</div>
<script type="text/javascript">
        //validar datos de entrada (por lo menos los campos requeridos)
        //realizar submit ajax y mostrar un cartel de datos guardados ->escenario exitoso
        //mostrar error o valores incorrectos
        
        var HabitsWidget = (function(){
            
			return {

				init : function(){
					$j("#reset").click(PatientWidget.backToList);
					$j("#submit").click(this.sendData);
					this.startChecks();
				},
				startChecks : function(){
					$j('#habits input[type="checkbox"]').click(function(){
						var aCheck = $j(this); 
						if(aCheck.is(':checked')) aCheck.val(1);
						else aCheck.val(0);
					});	
				},
				sendData : function(){

					var url = $j("#habits").attr("action");
	                //var data = $("#personal-info :input[value][value!='.']").serializeArray();
	                
	                var data = $j("#habits :input").serializeArray();
	                var json = {};
	                jQuery.map(data, function(n, i){
	                        json[n['name']] = n['value'];
	                });
					console.log(json);
	                $j.post(url,json,function(response){
	                        console.log(response);
	                        return false;
	                });
	                
	                
				}
			};
       }());
        
       HabitsWidget.init();        
</script>